<?php

use Fisharebest\Webtrees\Http\RequestHandlers\AddParentToIndividualPage;
use Fisharebest\Webtrees\Http\RequestHandlers\AddSpouseToFamilyPage;
use Fisharebest\Webtrees\I18N;

?>

<div class="d-flex">
    <div class="wt-chart-horizontal-spacer">
        <div class="wt-chart-horizontal-line"></div>
    </div>
    <div class="align-self-center">
        <div class="d-flex">
            <div class="wt-chart-horizontal-spacer">
                <div class="wt-chart-horizontal-first-parent"></div>
            </div>

            <div class="align-self-center">
                <?php if ($individual === null) : ?>
                    <?= view('chart-box', ['individual' => null]) ?>
                <?php elseif ($family === null) : ?>
                    <div class="wt-chart-box">
                        <?php if ($individual->canEdit()) : ?>
                            <a class="btn btn-link" href="<?= e(route(AddParentToIndividualPage::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'gender' => 'M'])) ?>">
                                <?= I18N::translate('Add a father') ?>
                            </a>
                        <?php endif ?>
                    </div>
                <?php elseif ($family->husband() === null) : ?>
                    <div class="wt-chart-box">
                        <?php if ($family->canEdit()) : ?>
                            <a class="btn btn-link" href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'famtag' => 'HUSB'])) ?>">
                                <?= I18N::translate('Add a father') ?>
                            </a>
                        <?php endif ?>
                    </div>
                <?php else : ?>
                    <?= view('chart-box', ['individual' => $family ? $family->husband() : null]) ?>
                <?php endif ?>
            </div>
        </div>

        <div class="d-flex">
            <div class="wt-chart-horizontal-spacer">
                <div class="wt-chart-horizontal-last-parent"></div>
            </div>

            <div class="align-self-center">
                <?php if ($individual === null) : ?>
                    <?= view('chart-box', ['individual' => null]) ?>
                <?php elseif ($family === null) : ?>
                    <div class="wt-chart-box">
                        <?php if ($individual->canEdit()) : ?>
                            <a class="btn btn-link" href="<?= e(route(AddParentToIndividualPage::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'gender' => 'F'])) ?>">
                                <?= I18N::translate('Add a mother') ?>
                            </a>
                        <?php endif ?>
                    </div>
                <?php elseif ($family->wife() === null) : ?>
                    <div class="wt-chart-box">
                        <?php if ($family->canEdit()) : ?>
                            <a class="btn btn-link" href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'famtag' => 'WIFE'])) ?>">
                                <?= I18N::translate('Add a mother') ?>
                            </a>
                        <?php endif ?>
                    </div>
                <?php else : ?>
                    <?= view('chart-box', ['individual' => $family ? $family->wife() : null]) ?>
                <?php endif ?>
            </div>
        </div>
    </div>
    <?php if ($family !== null) : ?>
        <div class="align-self-center">
            <a class="btn btn-text" href="<?= e($family->url()) ?>" title="<?= strip_tags($family->fullName()) ?>">
                <?= view('icons/arrow-right') ?>
            </a>
        </div>
    <?php endif ?>
</div>

